﻿package {
	/*
	** @name			: ReflexTest.as
	** @description		: main document class for carpet.fla
	** @author			: =undo=
	** @web				: http://www.undolog.com
	*/
	
	//
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	//
	import undolibrary.ui.*;
	//
	public class ReflexTest extends Sprite {
		
		protected var __panel:Sprite;
		
		/*
		** @constructor
		*/
        public function ReflexTest() {
			stage.scaleMode	= StageScaleMode.NO_SCALE;
			stage.align 	= StageAlign.TOP_LEFT;
			addEventListener( Event.ADDED_TO_STAGE, init );
        }
		
		/*
		** @name		: init()
		*/
		protected function init(e:Event = null):void {
			initControls();
		}
		
		/*
		** @name		: initControls()
		*/
		protected function initControls():void {
			__panel				= new Sprite();
			addChild( __panel );
			__panel.y			= stage.stageHeight - 90;
			with(__panel.graphics) {
				beginFill(0x222233);
				drawRect(0, 0, stage.stageWidth, 90);
				endFill();
			}
			
			// 
			var r1:Object 	= createKnob( 80, 8, "RIFLESSO Y", -100, 100, undolog_mc.reflexOffset);
			r1.knob.addEventListener( KnobEvent.CHANGE, 
				function( e:KnobEvent):void {
					undolog_mc.reflexOffset		= e.Value;
					r1.text.text				= sub( String( undolog_mc.reflexOffset ) ); 
				}
			);
			// 
			var r2:Object 	= createKnob( 80, r1.knob.y+20, "GRADEINTE", 0, 255, undolog_mc.gradientOffset );
			r2.knob.addEventListener( KnobEvent.CHANGE, 
				function( e:KnobEvent):void {
					undolog_mc.gradientOffset	= Math.floor( e.Value );
					r2.text.text				= String( Math.floor( e.Value ) ); 
				}
			);
			// 
			var r3:Object 	= createKnob( 80, r2.knob.y+20, "ALPHA", 0, 1, undolog_mc.alphaOffset );
			r3.knob.addEventListener( KnobEvent.CHANGE, 
				function( e:KnobEvent):void {
					undolog_mc.alphaOffset	= e.Value;
					r3.text.text			= sub(String( e.Value ) ); 
				}
			);			
			// 
			var ck1:Check 	= createCheck( 80, r3.knob.y+20, "RADIALE", undolog_mc.gradientRadial );
			ck1.addEventListener(CheckEvent.CHANGE, 
				function( e:CheckEvent):void {
					undolog_mc.gradientRadial = e.Value;
				}
			);
		}
		
		/*
		** @name		: createKnob()
		*/
		protected function createKnob(x:Number, y:Number, l:String, min:Number, max:Number, v:Number):Object {
			var knob:Knob 		= new Knob();
			var tlabel:Testo	= new Testo();
			var tvalue:Testo	= new Testo();
			__panel.addChild( tlabel );
			__panel.addChild( tvalue);
			__panel.addChild( knob );
			knob.x				= x;
			knob.y				= y;
			knob.Height			= 8;
			knob.KnobWidth		= 10;
			knob.KnobHeight		= 12;
			knob.KnobColor		= 0xff9900;
			knob.Min 			= min;
			knob.Max 			= max;
			knob.Value			= v;
			tlabel.x			= x-70;
			tlabel.y			= y-2;
			tvalue.x			= knob.x + knob.Width + 4;
			tvalue.y			= tlabel.y;
			tlabel.text.text	= l.toUpperCase();
			tvalue.text.text	= String( v );
			return { knob: knob, text: tvalue.text };
		}
		
		/*
		** @name		: createCheck()
		*/
		protected function createCheck(x:Number, y:Number, l:String, v:Boolean):Check {
			var ck:Check 		= new Check();
			var tlabel:Testo	= new Testo();
			__panel.addChild( tlabel );
			__panel.addChild( ck );
			ck.x				= x;
			ck.y				= y;
			ck.Value			= v;
			tlabel.x			= x-70;
			tlabel.y			= y-2;
			tlabel.text.text	= l.toUpperCase();
			return ck;
		}
		
		/*
		** @name		: sub()
		*/
		protected function sub(s:String, v:uint = 4):String {
			return ( (s.length > v)?s.substr(0,v):s );
		}
	}
}